package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.enums.AttackTypeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.model.attack.AttackEntity;
import com.loveprogrammer.eternity.model.attack.AttackResult;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @version 1.0.0
 * @description: 闪电链
 * @author: eric
 * @date: 2022-08-16 16:53
 **/
public class SkillLightingChain extends AbstractSkill{

    public SkillLightingChain(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();

        List<Character> characters = new ArrayList<>();
        // 攻击所有的地方单位
        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】攻击了 ").append("所有敌方目标 每次伤害递减30%\n");
        int power = getHarm(character);

        // 暴击检测 提升200%的伤害 几率 技巧 + 500 / 技巧 + 6000
        boolean crit = critCheck(character);
        for (Character defence : defences) {
            AttackResult attackResult = defence.defence(new AttackEntity(this,power, AttackTypeEnum.THUNDER));
            computeHarm(builder,crit,defence,attackResult, character, attack, defences);
            power = (int) (power * 0.7);
        }

        result.setValue(characters);
        result.setKey(builder.toString());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) (character.getMagic() * 1.5 * ((getBaseHarm() + getLevel() * 2) / 100));
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }

    @Override
    public boolean check(Character character) {
        if(restInterval() <= 0) {
            return true;
        }
        return false;
    }

    @Override
    public int opportunityPassive() {
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每5 升一级
        if(characterLevel % 5 == 0){
            return true;
        }
        return false;
    }

    @Override
    public int defaultHarm() {
        setBaseHarm(120);
        return 120;
    }
}
